<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setAttribute("contextPath",request.getContextPath());
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<style type="text/css">
		.randl{
			position: absolute;
			top:30;
			left:1200;
		}
		.logout{
			position:absolute;
			top:30;
			left:1200;
		}
		
		h4{
			color:orange;
			position:absolute;
			top:7;
			left:20;
		}
		
		.nickname{
			color:blue;
		}
		.selfInfo{
			color:green;
			position:absolute;
			top:30;
			left:900;
		}
		.wealth{
			color:red;
		}
		.search{
			position:absolute;
			top:280px;
			left:400px;
			margin-left:auto;
			margin-right:auto;
		}
		.typelist{
			position:absolute;
			top:380px;
			left:410px;
			margin-left:auto;
			margin-right:auto;
			width:450px;
		}
		.image
		{
			position:absolute;
			top:150px;
			left:460px;
		}
	</style>
	<script type="text/javascript" src="${contextPath}/js/jquery-1.7.2.js"></script>
	<script type="text/javascript">
		$(document).ready(function (){
			$randl = $("#randl");
			$logoutA = $("#logoutA");
			$selfInfo = $("#selfInfo");
			$selfHome = $("#selfHome");
			$wealth = $("#wealth");
			$randl.css("display","none");
			$logoutA.css("display","none");
			$selfInfo.css("display","none");
			$nickname = $("#nickname");
			$.ajax({
				url: "${contextPath}/user/getLoginInfo",
				type:"POST",
				success:function(o){
			 		if(o!=null && o.loginStatus == true) {
			 			$nickname.text(o.nickname+", ");
				 		$randl.css("display","none");
				 		$logoutA.css("display","inline");
				 		$wealth.text(o.wealth+"￥");
				 		$selfInfo.css("display","inline");
				 		$selfHome.attr("href","user/selfHome/"+o.nickname);
			 		}else{
						$randl.css("display","inline");
				 		$logoutA.css("display","none");
				 		$selfInfo.css("display","none");
			  		}
				},
				error:function(o){
					alert("error");
				}
			});	
		});
		
		
		
	</script>
 </head>
  
  <body>	
  	<div>
   		<h4><span id="nickname" class="nickname"></span>欢 迎 来 到 慧 驾 书 城！</h4>
   		<div id="randl" class="randl">
   			<a id="loginA" href="login.jsp">登陆</a>|<a id="registerA" href="register.jsp">注册</a>
   		</div>
   		<div id="selfInfo" class="selfInfo">
   			<a id="selfHome" class="selfHome" href="">个人中心</a>|钱包余额:<span id="wealth" class="wealth"></span>
   		</div>
  		<a id="logoutA" class="logout" href="logout">(^_^)/~~拜拜</a>
   	</div>
   	<div class="image">
   		<img alt="慧驾书城" src="${contextPath }/images/index.png" width="360px" height=120px>
   	</div>
   	<div class="search">
   		<form id="searchBooks" action="${contextPath}/book/bookListByKeyWord" method="post">
   			<input id="keyword" name="keyword" type="text" style="width:380px;height:30px"/>
   			<button id="submit" type="submit" style="width:120px;height:30px">搜索一下</button>
   		</form>
   	</div>
   	<div class="typelist">
   		<c:forEach items="${types}" var="type">
   			<a href="${contextPath }/book/bookListByType/${type.id}" style="text-decoration : none ">${type.name}/</a>
   		</c:forEach>
   	</div>
  </body>
</html>
